package cn.qingxuntech.console.service

import cn.qingxuntech.console.entity.SspSpace
import cn.qingxuntech.console.mapper.SspSpaceMapper
import cn.qingxuntech.console.model.request.SspSpaceRequest
import com.mybatisflex.core.paginate.Page
import com.mybatisflex.core.query.QueryWrapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class SspSpaceService {

    @Autowired
    lateinit var sspSpaceMapper: SspSpaceMapper

    fun list(sspSpaceRequest: SspSpaceRequest): List<SspSpace> {

        return sspSpaceMapper.selectListByQuery(QueryWrapper.create()
            .eq(SspSpace::mediaId, sspSpaceRequest.mediaId)
            .orderBy(SspSpace::createTime, false))
    }

    fun page(sspSpaceRequest: SspSpaceRequest): Page<SspSpace> {
        return sspSpaceMapper.paginate(Page.of(sspSpaceRequest.current, sspSpaceRequest.size),
            QueryWrapper.create()
                .orderBy(SspSpace::createTime, false))
    }

}
